package ui.activity.mine.presenter;


import com.google.gson.Gson;

import net.ck.hzq.RealNameActivity;
import net.ck.hzq.SampleAct;
import net.ck.hzq.ShareActivity;
import net.ck.hzq.SmActivity;
import net.ck.hzq.WebviewActivity;
import net.ck.hzq.view.LearnMoreActivity;

import javax.inject.Inject;

import base.BaseBiz;
import coom.Constants;
import model.PersonalCenterBean;
import model.PersonalCenterParamBean;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import ui.activity.home.RedBallListAct;
import ui.activity.mine.AboutAct;
import ui.activity.mine.ComplaintAct;
import ui.activity.mine.ManagerAddressAct;
import ui.activity.mine.MessageAct;
import ui.activity.mine.MyWalletAct;
import ui.activity.mine.PersonalCenterAct;
import ui.activity.mine.PresentRecordAct;
import ui.activity.mine.SettingAct;
import ui.activity.mine.YinsiAct;
import ui.activity.mine.biz.MineBiz;
import ui.activity.mine.contract.MineContract;
import ui.activity.order.OrderAct;
import ui.activity.profit.KF5CustomerAct;

/**
 * Created by chenjian on 19/2/26
 */

public class MinePresenter implements MineContract.Presenter {

    MineContract.View view;
    MineBiz mineBiz;
    private boolean mNeedAuth = true;


    @Inject
    public MinePresenter(MineContract.View view) {
        this.view = view;
    }


    @Override
    public void setBiz(BaseBiz biz) {
        mineBiz = (MineBiz) biz;
    }


    @Override
    public void getUserIncome(String id) {
        PersonalCenterParamBean p = new PersonalCenterParamBean();
        p.setCustomId(id);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(p));
        mineBiz.getUserIncome(requestBody, new BaseBiz.Callback<PersonalCenterBean.DataBean>() {
            @Override
            public void onSuccess(PersonalCenterBean.DataBean info) {
                if (info.getCustom().getIsRealNameAuthenticationed() == 1) {
                    mNeedAuth = false;
                } else {
                    mNeedAuth = true;
                }
                Constants.NeedAuth = mNeedAuth;
                view.upDateUI(info);
            }

            @Override
            public void onFailure(PersonalCenterBean.DataBean info) {

            }
        });
    }

    @Override
    public void toUser() {
        view.startAct(PersonalCenterAct.class, null);
    }

    @Override
    public void toShare() {
        if (mNeedAuth) {
            view.showMsg("请进行实名认证");
            return;
        }
        view.startAct(ShareActivity.class, null);
    }

    @Override
    public void toOrder() {
        if (mNeedAuth) {
            view.showMsg("请进行实名认证");
            return;
        }
        view.startAct(OrderAct.class, null);
    }

    @Override
    public void toAddress() {
        if (mNeedAuth) {
            view.showMsg("请进行实名认证");
            return;
        }
        view.startAct(ManagerAddressAct.class, null);
    }

    @Override
    public void toAuthentication() {


//        view.startAct(SampleAct.class, null);

//
        if (!mNeedAuth) {
            view.showMsg("您已实名认证成功");
            return;
        }
        view.startAct(RealNameActivity.class, null);

    }

    @Override
    public void toWallet() {
        if (mNeedAuth) {
            view.showMsg("请进行实名认证");
            return;
        }
        view.startAct(MyWalletAct.class, null);
    }

    @Override
    public void toMessage() {
        if (mNeedAuth) {
            view.showMsg("请进行实名认证");
            return;
        }
        view.startAct(MessageAct.class, null);
    }

    @Override
    public void toComplaint() {
        if (mNeedAuth) {
            view.showMsg("请进行实名认证");
            return;
        }
        view.startAct(ComplaintAct.class, null);
    }

    @Override
    public void toAbout() {
        if (mNeedAuth) {
            view.showMsg("请进行实名认证");
            return;
        }
        view.startAct(AboutAct.class, null);
    }

    @Override
    public void toSetting() {
        view.startAct(SettingAct.class, null);
    }

    @Override
    public void toyinsi() {
        view.startAct(YinsiAct.class, null);
    }

    @Override
    public void toRedball() {
        if (mNeedAuth) {
            view.showMsg("请进行实名认证");
            return;
        }
        view.startAct(RedBallListAct.class, null);
    }
    @Override
    public void toMoreSupport() {
        if (mNeedAuth) {
            view.showMsg("请进行实名认证");
            return;
        }
        view.startAct(LearnMoreActivity.class, null);
    }

    @Override
    public void toSupportOnline() {
        if (mNeedAuth) {
            view.showMsg("请进行实名认证");
            return;
        }
        view.startAct(KF5CustomerAct.class, null);
    }

    @Override
    public void toTiXian() {
        if (mNeedAuth) {
            view.showMsg("请进行实名认证");
            return;
        }
        view.startAct(PresentRecordAct.class, null);
    }
}
